package capricornus.actor.utils
{
	public class Direction
	{
		public static const RIGHT:int = 0;
		public static const RIGHT_DOWN:int = 1;
		public static const DOWN:int = 2;
		public static const LEFT_DOWN:int = 3;
		public static const LEFT:int = 4;
		public static const LEFT_UP:int = 5;
		public static const UP:int = 6;
		public static const RIGHT_UP:int = 7;
		
		public function Direction()
		{
		}
		
		/**
		 * 获取从点arr1指向arr2的方向 
		 * @param arr1
		 * @param arr2
		 * @return 
		 * 
		 */		
		public static function getDirectPointToPoint( arr1:Array, arr2:Array ):int
		{
			var x:int = arr2[0] - arr1[0];
			var y:int = arr1[1] - arr2[1];
			if( x != 0 )
			{
				var a:Number = Math.abs(y / x);
				if( a < 0.41421356237309503 )
				{
					if( x > 0 ) return RIGHT;
					else return LEFT;
				}
				else if( a > 2.414213562373095 )
				{
					if( y > 0 ) return UP;
					return DOWN;
				}
				else if( a > 0.4142135623730958 && a < 2.414213562373095 )
				{
					if( x > 0 )
					{
						if( y > 0 ) return RIGHT_UP;
						return RIGHT_DOWN;
					}
					else
					{
						if( y > 0 ) return LEFT_UP;
						return LEFT_DOWN;
					}
				}
			}
			else if( y > 0 )
			{
				return UP;
			}
			
			return DOWN;
		}
	}
}